package net.comm.servlet;




import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

import net.comm.common.GlbFinal;
import net.comm.util.Function;
import net.comm.util.StringUtil;



public class LogOFF extends HttpServlet {

	/**

	 * 

	 */

	private static final long serialVersionUID = -3074767038737131093L;



	/**
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest,

	 *      HttpServletResponse)

	 */

	public void doGet(HttpServletRequest request, HttpServletResponse response)

			throws ServletException, IOException {
		
		doPost(request, response);
		
	}

	/*
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest,

	 *      HttpServletResponse)

	 */

	public void doPost(HttpServletRequest request, HttpServletResponse response)

			throws ServletException, IOException {

		try {

			request.setCharacterEncoding("UTF-8");
			
			PrintWriter out = response.getWriter();


			// 输出页面头部

			response.setContentType("text/html");

			String[] js1 = new String[1];

			js1[0] = "/js/common.js";
			
			out.println(Function.getHtmlHead("用户退出",	"/images/printimg.gif", js1).toString());

			String nexturl = StringUtil.getValue(request.getParameter("nexturl"));
			
			request.getSession().removeAttribute(GlbFinal.SESSION_USERID);
			request.getSession().removeAttribute(GlbFinal.SESSION_NAME);
			request.getSession().removeAttribute(GlbFinal.SESSION_USERTYPE);
		
			request.getSession().invalidate();
			
			Cookie cookies[] = request.getCookies();
			if(cookies != null){
				String cookpath = "/";

				String cookieName=GlbFinal.SESSION_USERID;
				Cookie cookie = new Cookie(cookieName, null); 
				cookie.setMaxAge(-1);
				cookie.setPath(cookpath);
				response.addCookie(cookie); 		
				
				cookieName=GlbFinal.SESSION_NAME;
				cookie = new Cookie(cookieName, null); 
				cookie.setMaxAge(-1);
				cookie.setPath(cookpath);
				response.addCookie(cookie); 		

				cookieName=GlbFinal.SESSION_USERTYPE;
				cookie = new Cookie(cookieName, null); 
				cookie.setMaxAge(-1);
				cookie.setPath(cookpath);
				response.addCookie(cookie); 					
			}
			
			out.println("</body>");
			out.println("</html>");
			
			if(nexturl.equals("")){

				response.sendRedirect( GlbFinal.FOLDER_INSTALL + "/index.jsp");
			}else{
				
				response.sendRedirect(nexturl);
			}			

		} catch (Exception e) {

			e.printStackTrace();

		}

	}
}

